package com.outstanding.ifml.warpper;

import com.outstanding.ifml.exception.IFMLException;


/**
 * 一个单词源
 * @author chenzhixuan
 *
 */
public abstract class AbstractToken implements Token {

	protected StringBuffer literals = new StringBuffer();

	protected TokenType type;

	
	// 0 初始；1正在构建变量； 正在构建值；完成
	protected State state = State.init;

	public State getState() {
		return state;
	}
	public void complete() {
		this.state = State.finish;
	}

	public boolean isCompleted() {
		return this.state == State.finish;
	}

	public TokenType getType() {
		return type;
	}

	public AbstractToken(TokenType type) {
		this.type = type;
	}

	

	public String getLiteral() {
		if(this.literals.length() >0){
			return this.literals.toString();
		}else{
			return null;
		}
	}
	
	public void setLiteral(String str) {
		literals.append(str);
	}
	@Override
	public String toString() {
		return "Token literals=" + literals + ", type=" + type + ", state=" + state + "";
	}
	
	

}
